package com.test.daily.leetcode.y2022.m05.day0524.v01;

/**
 * @descriptions: Solution
 * @author: Tom
 * @date: 2022/5/24 上午 10:23
 * @version: 1.0
 */
public class Solution {

      public static class TreeNode {
          int val;
          TreeNode left;
          TreeNode right;
          TreeNode() {}
          TreeNode(int val) { this.val = val; }
          TreeNode(int val, TreeNode left, TreeNode right) {
              this.val = val;
              this.left = left;
              this.right = right;
          }
      }

    public boolean isUnivalTree(TreeNode root) {
        if(root == null){
            return false;
        }
        return inJudge(root, root.val);
    }
    public static boolean inJudge(TreeNode root, int pre){
          boolean left = true;
          boolean right = true;
          left = left && (root.val == pre);
          if(root.left != null){
              left = inJudge(root.left, pre) && left;
          }
          if(root.right != null){
              right = inJudge(root.right, root.val);
          }
          return left && right;
    }
}
